package com.fenghuajueli.libbasecoreui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.fenghuajueli.libbasecoreui.R;

import java.util.ArrayList;

/**
 * vip描述功能适配器
 */
public class PictureAdapter extends RecyclerView.Adapter<PictureAdapter.ViewHolder> {

    private final ArrayList<String> data;
    private Context context;
    private OnItemClickLitener mOnItemClickLitener;

    public PictureAdapter(Context context, ArrayList<String> data) {
        this.context = context;
        this.data = data;
    }

    //定义点击接口
    public interface OnItemClickLitener {
        void onItemClick(int position);
    }

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_upload_pic, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        Glide.with(context).load(data.get(position)).into(holder.img_add);
        holder.img_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private  ImageView img_add,img_del;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img_add = itemView.findViewById(R.id.image_add);
            img_del = itemView.findViewById(R.id.image_del);
        }
    }
}